<template>
  <div>
    <h1>评论管理</h1>
    <el-table :data="tableData" style="width: 100%">
      <el-table-column
        prop="userName"
        label="用户名称"
        width="180"
      ></el-table-column>
      <el-table-column
        prop="articleTitle"
        label="文章标题"
        width="180"
      ></el-table-column>
      <el-table-column
        prop="commentContent"
        label="评论内容"
        width="180"
      ></el-table-column>
      <el-table-column
        prop="createTime"
        label="创建时间"
        width="180"
      ></el-table-column>
      <el-table-column
        prop="checkFlag"
        label="审核状态"
        width="180">
        <template slot-scope="scop">
          <span v-if="scop.row.checkFlag === 0">审核中</span>
          <span v-if="scop.row.checkFlag === 1">审核通过</span>
          <span v-if="scop.row.checkFlag === 2">未通过</span>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button
            v-if="scope.row.checkFlag === 0"
            size="mini"
            type="danger"
            @click="adopt(scope.$index, scope.row)"
          >
            通过
          </el-button>
          <el-button
            v-if="scope.row.checkFlag === 0"
            size="mini"
            type="danger"
            @click="noAdopt(scope.$index, scope.row)"
          >
            不通过
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="block">
      <el-pagination
        :page-sizes="[1, 3, 5, 7]"
        :current-page="pageNum"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      ></el-pagination>
    </div>
  </div>
</template>

<script>
  import { getUnreviewedCommentList, checkComment } from '@/api/bbs'
  export default {
    name: 'Index',
    data() {
      return {
        pageNum: 1,
        pageSize: 2,
        total: 20,
        tableData: [
          {
            commentId: '',
            articleId: '',
            articleTitle: '',
            userId: '',
            userName: '',
            commentContent: '',
            fatherId: '',
            createTime: '',
            updateTime: '',
            delFlag: '',
            checkFlag: '',
          },
        ],
      }
    },
    mounted() {
      this.getUnreviewedCommentLists()
    },
    methods: {
      getUnreviewedCommentLists(){
        getUnreviewedCommentList(this.pageNum,this.pageSize).then((res) => {
          console.log(res)
          this.tableData = res.data
          this.total = res.total
        })
      },
      handleSizeChange(val) {
        console.log(`每页 ${val} 条`)
        this.pageSize = val
        this.getUnreviewedCommentLists()
      },
      handleCurrentChange(val) {
        console.log(`当前页: ${val}`)
        this.pageNum = val
        this.getUnreviewedCommentLists()
      },
      adopt(index, row) {
        console.log(index, row)
        checkComment(1, row).then((res) => {
          console.log(res)
          this.getUnreviewedCommentLists()
        })
      },
      noAdopt(index, row) {
        console.log(index, row)
        checkComment(2, row).then((res) => {
          console.log(res)
          this.getUnreviewedCommentLists()
        })
      },
    },
  }
</script>

<style scoped></style>
